package bspay

import (
	"net/http"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/logic/pay/bspay"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"github.com/zeromicro/go-zero/rest/httpx"
)

// bspay代付回调通知
func BspayPayoutNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.BsPayoutNotifyReq
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := bspay.NewBspayPayoutNotifyLogic(r.Context(), svcCtx)
		_, err := l.BspayPayoutNotify(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			w.Write([]byte("success"))
		}
	}
}
